package com.sg.service.impl;

import com.github.pagehelper.PageHelper;
import com.sg.bean.Message;
import com.sg.dao.MessageDao;
import com.sg.dao.UsedDao;
import com.sg.service.MessageService;
import com.sg.service.UsedService;
import com.sg.vo.MessageVO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @author zl
 * 评论业务逻辑实现类
 */
@Service
public class MessageServiceImpl implements MessageService {
    Logger logger = Logger.getLogger(MessageServiceImpl.class);

    @Autowired
    MessageDao messageDao;
    @Autowired
    UsedDao usedDao;
    @Override
    public List<MessageVO> findByuId(int uId) {
        return messageDao.findByuId(uId);
    }

    @Override
    public List<MessageVO> findByuIdPage(int uId, int pageNum, int pageSize) {
        //开启分页
        PageHelper.startPage(pageNum,pageSize);
        return messageDao.findByuId(uId);
    }

    @Override
    public List<MessageVO> findAll(int pageNum,int pageSize) {
        //开启分页
        PageHelper.startPage(pageNum,pageSize);
        return messageDao.findAll();
    }

    @Override
    public List<MessageVO> findByusedId(int usedId) {
        return messageDao.findByusedId(usedId);
    }

    @Override
    public boolean delete(int[] arrays) {
        return messageDao.delete(arrays)>0?true:false;
    }

    @Override
    //@Transactional(propagation = Propagation.REQUIRED)
    public int deleteByUsedId(int[] array) {
        int i1 =  messageDao.deleteByUsedId(array);
        return i1;
    }

    @Override
    public boolean add(Message message) {
        return messageDao.add(message)>0?true:false;
    }
}
